﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZLDC.Common.Estate;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ZLDC.Topo.BLL.Estate
{
    public class lp_PackageSet
    {
                                                public static DataSet GetPckList(string deptlist)
        {
            string sql = "";
            sql = "select * from lp_Package where createuser=("+
                    "select  top 1 CreateUser from lp_Package where DeptID in (" + deptlist + ") and Other2 in ('区域', '营业部') and" +
                    " Other4='1' order by other2"+
                    ")";
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            return ds;
        }

        public static void BtnUpdate(Repeater RpList, Page p,  TextBox txttext,string depttype, HiddenField hiduserid)
        {
            string sql = "";
            string name = txttext.Text;
            string namevalue = txttext.Text + DateTime.Now;
            int i = 0;
            Random ran = new Random();
            int RandKey = ran.Next(100);
            foreach (RepeaterItem Item in RpList.Items)
            {
                CheckBox ckb = (CheckBox)Item.FindControl("ckb");
                HiddenField hidid = (HiddenField)Item.FindControl("hidid");
                TextBox txtQuantity = (TextBox)Item.FindControl("txtQuantity");
                TextBox txtScore = (TextBox)Item.FindControl("txtScore");
                HiddenField Remark = (HiddenField)Item.FindControl("hidRemark");
                HiddenField Name = (HiddenField)Item.FindControl("hidName");
                HiddenField Point = (HiddenField)Item.FindControl("hidPoint");
                HiddenField hidCompleteNum = (HiddenField)Item.FindControl("hidCompleteNum");
                HiddenField Unit = (HiddenField)Item.FindControl("hidUnit");
                HiddenField TypeName = (HiddenField)Item.FindControl("TypeName");
                HiddenField hidPackageID = (HiddenField)Item.FindControl("hidPackageID");
                TextBox txtSinglePoint = (TextBox)Item.FindControl("txtSinglePoint");
                int tr = 0; 
                i++;
                int eab = 0;
                if (ckb.Checked)
                {
                    tr = 1;
                }
                if (!ckb.Enabled)
                {
                    eab = 1;
                }
                sql += "insert into lp_Package(Other3,Name,BasisCode,CreateUser,CreateTime,Remark,Quantity,Choose,DeptID,CompleteNum,Score,BasisName,Point,Unit,Other1,Other2,Choosesj,SinglePoint) values (";
                sql += "'" + namevalue + "','" + (txttext.Text) + "','" + hidid.Value + "'," + _Utility.GetInfoBySession().m_sUserID + ",'" + DateTime.Now + "',";
                sql += "'" + Remark.Value + "'," + (txtQuantity.Text == "" ? "0" : txtQuantity.Text) + "," + tr + "," + _Utility.GetInfoBySession().m_sDeptID + "," + (hidCompleteNum.Value == "" ? "0" : hidCompleteNum.Value) + "," + txtScore.Text + ",'" + Name.Value + "'," + Point.Value + ",'" + Unit.Value + "','" + TypeName.Value + "','" + depttype + "'";
                sql += ",'" + eab + "'," + (txtSinglePoint.Text == "" ? "0" : txtSinglePoint.Text) + "";
                sql += ");";
                    
              
            }
            if (i > 0)
            {
                using (_Database db = new _Database("estate"))
                {
                    ZLDC.DAL.Estate.lp_Basis.SqlQuery(sql, db);
                }
                p.Response.Write("<script>alert('保存成功！');window.location.href='../lp_Package.aspx';</script>");
            }
        }
    }
}
